<!doctype html>
<html lang="zh-CN">
	<head>
		<title>NTC分压计算器 - 嵌入式工具集</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<!-- 引入Tailwind CSS -->
		<script src="https://cdn.tailwindcss.com"></script>
		<!-- 以下为浏览器中的配置，正式 编译之后请注释掉这段-->
		<link rel="stylesheet" href="../styles/styles.css" />
		<!-- 以下为LCEDA中的配置，正式 编译之后请勿注释这段-->
		<link rel="stylesheet" href="/iframe/styles/styles.css" />
		<style>
			/* NTC分压计算器特定样式 - 小窗口适配 */
			.input-container {
				display: block;
				gap: 1rem;
				margin-bottom: 1rem;
			}

			/* 输入框样式 - 小窗口优化 */
			.ntc-divider-calculator .input-label {
				min-width: 100px;
				font-size: 0.9rem;
			}

			/* 图标样式 - 确保在嘉立创EDA环境中正常显示 */
			.fa {
				display: inline-block;
				width: 1em;
				height: 1em;
				font-size: inherit;
				line-height: 1;
				vertical-align: middle;
				text-align: center;
			}

			.fa-calculator:before {
				content: '🧮';
				font-size: 1.1em;
			}

			.fa-refresh:before {
				content: '↺';
				font-size: 1.1em;
			}

			.fa-info-circle:before {
				content: 'ℹ️';
				font-size: 1em;
			}

			/* 增强按钮样式 - 小窗口适配 */
			.btn-primary {
				background-color: #0891b2;
				color: white;
				border: none;
				border-radius: 6px;
				padding: 0.6rem;
				cursor: pointer;
				transition: all 0.2s ease;
				font-weight: 600;
				font-size: 0.9rem;
				display: flex;
				align-items: center;
				justify-content: center;
				box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
				height: 3rem;
				width: 100%;
			}

			.btn-secondary {
				background-color: #f59e0b;
				color: white;
				border: none;
				border-radius: 6px;
				padding: 0.6rem;
				cursor: pointer;
				transition: all 0.2s ease;
				font-weight: 600;
				font-size: 0.9rem;
				display: flex;
				align-items: center;
				justify-content: center;
				box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
				height: 3rem;
				width: 100%;
			}

			/* 美化公式框 - 小窗口适配 */
			.formula-box {
				background-color: #f8fafc;
				border-radius: 8px;
				padding: 1rem;
				margin-bottom: 1rem;
				font-family: 'SF Pro Text', 'Inter', monospace;
				text-align: center;
				border: 1px solid #e2e8f0;
				box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
				max-width: 100%;
				overflow-x: auto;
			}

			.formula-title {
				font-weight: 700;
				margin-bottom: 0.5rem;
				color: #374151;
				font-size: 0.9rem;
			}

			.formula-row {
				color: #4b5563;
				font-size: 0.8rem;
				line-height: 1.5;
				margin-bottom: 0.5rem;
			}

			/* 优化的结果卡片布局 - 参照LED计算器 */
			.result-cards {
				display: grid;
				grid-template-columns: repeat(2, 1fr);
				gap: 1.25rem;
				margin: 1.5rem 0;
			}

			/* 优化的结果卡片样式 - 参照LED计算器 */
			.result-card {
				border-radius: 12px;
				padding: 1.5rem;
				text-align: center;
				transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
				color: white;
				position: relative;
				overflow: hidden;
			}

			/* 卡片悬停效果 */
			.result-card:hover {
				transform: translateY(-5px) scale(1.03);
				box-shadow:
					0 20px 25px -5px rgba(0, 0, 0, 0.1),
					0 10px 10px -5px rgba(0, 0, 0, 0.04);
			}

			/* 卡片标题样式 */
			.result-title {
				font-size: 0.9rem;
				opacity: 0.95;
				margin-bottom: 0.75rem;
				font-weight: 600;
				letter-spacing: 0.025em;
			}

			/* 卡片数值样式 */
			.result-value {
				font-size: 1.5rem;
				font-weight: 700;
				margin-bottom: 0.5rem;
				text-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
				font-family: 'SF Pro Text', 'Inter', sans-serif;
				font-weight: 800;
			}

			/* 特定结果卡片的背景颜色和阴影 */
			.ntc-resistance-card {
				background: linear-gradient(135deg, #93c5fd 0%, #60a5fa 100%);
				color: #1e40af;
				box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.3);
			}

			.voltage-card {
				background: linear-gradient(135deg, #6ee7b7 0%, #34d399 100%);
				color: #065f46;
				box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.3);
			}

			.adc-value-card {
				background: linear-gradient(135deg, #fde68a 0%, #fcd34d 100%);
				color: #92400e;
				box-shadow: 0 10px 25px -5px rgba(245, 158, 11, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.3);
			}

			.percentage-card {
				background: linear-gradient(135deg, #c4b5fd 0%, #a78bfa 100%);
				color: #5b21b6;
				box-shadow: 0 10px 25px -5px rgba(139, 92, 246, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.2);
			}

			.ratio-card {
				background: linear-gradient(135deg, #fda4af 0%, #f87171 100%);
				color: #991b1b;
				box-shadow: 0 10px 25px -5px rgba(239, 68, 68, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.3);
			}

			.temperature-card {
				background: linear-gradient(135deg, #f472b6 0%, #db2777 100%);
				color: #7f1d1d;
				box-shadow: 0 10px 25px -5px rgba(219, 39, 119, 0.3);
				border: 1px solid rgba(255, 255, 255, 0.3);
			}

			/* 确保在插件环境中的兼容性 */
			body {
				margin: 0;
				padding: 0;
				font-size: 14px;
				max-width: 100%;
				overflow-x: hidden;
			}

			/* 主容器样式 - 小窗口适配 */
			.calculator-container {
				padding: 0.75rem !important;
				margin: 0 !important;
				width: 100% !important;
				box-sizing: border-box;
			}

			/* 标题样式 - 小窗口适配 */
			.calculator-container h2 {
				font-size: 1.2rem !important;
				margin-bottom: 1rem !important;
				padding: 0.5rem 0;
			}

			/* 计算模式选择 - 小窗口适配 */
			.my-6 {
				margin: 0.75rem 0 !important;
				padding: 0.75rem !important;
			}

			.text-lg {
				font-size: 1rem !important;
				margin-bottom: 0.5rem !important;
			}

			/* 输入框文本居中显示并添加背景色增强视觉效果 */
			.input-field input {
				text-align: center;
				font-size: 0.9rem;
				padding: 0.6rem;
				background-color: #f8fafc;
				border: 1px solid #e2e8f0;
				border-radius: 8px;
				transition: all 0.2s ease;
			}

			/* 输入框聚焦效果 */
			.input-field input:focus {
				background-color: #ffffff;
				border-color: #93c5fd;
				outline: none;
				box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
			}

			/* 输入组样式 - 小窗口适配 */
			.input-group {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 0.25rem;
				padding: 0.17rem 0;
			}

			/* 输入框单位样式 */
			.input-unit {
				margin-left: 0.5rem;
				font-size: 0.8rem;
				color: #6b7280;
			}

			/* 单位选择器样式 - 小窗口适配 */
			.unit-selector {
				font-size: 0.8rem !important;
				padding: 0.4rem 0.2rem !important;
			}

			/* 操作区域样式 - 小窗口适配 */
			.flex.items-center {
				flex-direction: column;
				gap: 0.5rem;
			}

			.flex-1 {
				width: 100%;
			}

			/* 实时更新复选框容器 */
			.bg-gray-50 {
				width: 100%;
				margin-bottom: 0.5rem;
				padding: 0.5rem;
			}

			/* 部分标题样式 */
			.section-title {
				font-size: 1rem !important;
				margin-bottom: 0.75rem !important;
			}

			/* 部分容器样式 */
			.section-container {
				margin-bottom: 1rem;
				padding: 0.75rem;
			}

			/* 页脚样式 */
			footer {
				margin-top: 1rem !important;
				font-size: 0.75rem;
				padding: 0.5rem 0;
			}

			/* 公式样式 - 小窗口适配 */
			.formula-row div {
				font-size: 0.75rem;
				padding: 0.5rem;
			}

			/* 参数说明样式 - 小窗口适配 */
			.formula-box ul {
				font-size: 0.75rem !important;
				line-height: 1.4;
				margin: 0.25rem 0 0 0.5rem !important;
				padding-left: 1rem !important;
			}

			.formula-box li {
				margin-bottom: 0.25rem;
			}
		</style>
	</head>
	<body class="bg-white min-h-screen p-2 font-sans">
		<div class="w-full mx-auto bg-white rounded-lg calculator-container ntc-divider-calculator">
			<h2 class="text-2xl font-bold text-primary mb-6 text-center">NTC分压计算器</h2>

			<!-- 计算模式选择 -->
			<div class="my-6 p-4 bg-blue-50 rounded-lg border border-blue-100">
				<div class="text-lg font-medium text-primary mb-3">计算模式选择</div>
				<div class="grid grid-cols-2 gap-4">
					<div class="flex items-center space-x-2">
						<input type="radio" id="mode-temp-to-adc" name="calc-mode" value="temp-to-adc" class="w-4 h-4 text-primary" />
						<label for="mode-temp-to-adc" class="cursor-pointer">模式一：温度→ADC</label>
					</div>
					<div class="flex items-center space-x-2">
						<input type="radio" id="mode-adc-to-temp" name="calc-mode" value="adc-to-temp" class="w-4 h-4 text-primary" checked />
						<label for="mode-adc-to-temp" class="cursor-pointer">模式二：ADC→温度</label>
					</div>
				</div>
			</div>

			<script>
				// 添加模式切换的事件监听器
				function updateInterfaceByMode() {
					const mode = document.querySelector('input[name="calc-mode"]:checked').value;
					const adcInputGroup = document.getElementById('adc-input-group');
					const temperatureInputGroup = document.getElementById('ntc-temperature').closest('.input-group');
					const temperatureKInputGroup = document.getElementById('ntc-temperature-k').closest('.input-group');
					const resistanceRtInputGroup = document.getElementById('ntc-resistance-rt').closest('.input-group');
					const adcResultCardTitle = document.querySelector('.adc-value-card .result-title');
					const adcValueCard = document.querySelector('.adc-value-card');
					const percentageCard = document.querySelector('.percentage-card');
					const temperatureCard = document.querySelector('.temperature-card');
					const ntcResistanceCard = document.querySelector('.ntc-resistance-card');

					// 获取公式元素
					const formula1 = document.getElementById('formula-1');
					const formula2 = document.getElementById('formula-2');
					const formula3 = document.getElementById('formula-3');
					const formula4 = document.getElementById('formula-4');
					const formula4Adc = document.getElementById('formula-4-adc');
					const formula6 = document.getElementById('formula-6');
					const paramsDescription = document.getElementById('params-description');

					// 控制输入框的显示/隐藏
					if (mode === 'temp-to-adc') {
						// 模式一：温度→ADC模式：显示温度和电阻输入框，隐藏ADC输入框
						temperatureInputGroup.style.display = 'flex';
						temperatureKInputGroup.style.display = 'flex';
						resistanceRtInputGroup.style.display = 'flex';
						adcInputGroup.style.display = 'none';
						adcResultCardTitle.textContent = 'ADCvalue'; // 修改卡片标题
						adcValueCard.style.display = 'block'; // 显示ADC值卡片
						percentageCard.style.display = 'block'; // 显示ADC百分比卡片
						temperatureCard.style.display = 'none'; // 隐藏温度卡片
						ntcResistanceCard.style.display = 'none'; // 隐藏NTC电阻卡片

						// 显示模式一：温度→ADC模式使用的公式
						formula1.style.display = 'block';
						formula2.style.display = 'block';
						formula4Adc.style.display = 'block';
						formula3.style.display = 'none';
						formula4.style.display = 'none';
						formula6.style.display = 'none';

						// 更新参数说明，只显示模式一：温度→ADC模式需要的参数
						paramsDescription.innerHTML = `
						<strong>参数说明：</strong>
						<ul style="margin: 5px 0 0 15px; padding-left: 20px; text-align: left; list-style-type: disc">
							<li>T：当前温度，单位是开尔文 (K)</li>
							<li>R<sub>t</sub>：是在温度T下的NTC电阻值</li>
							<li>T<sub>0</sub>：是参考温度（用户可设置，默认为25°C = 298.15K）</li>
							<li>R<sub>0</sub>：是NTC在参考温度T<sub>0</sub>下的标称电阻值</li>
							<li>B：是B值，由制造商提供</li>
							<li>V<sub>out</sub>：是输出电压，V<sub>CC</sub>是供电电压</li>
							<li>R<sub>fixed</sub>：是固定电阻值</li>
							<li>V<sub>ref</sub>：是ADC的参考电压</li>
							<li>ADC<sub>value</sub>：计算得到的ADC值</li>
							<li>ADC<sub>max</sub>：是ADC的最大值</li>
						</ul>
					`;
					} else {
						// 模式二：ADC→温度：只显示ADC输入框，隐藏其他三个输入框
						temperatureInputGroup.style.display = 'none';
						temperatureKInputGroup.style.display = 'none';
						resistanceRtInputGroup.style.display = 'none';
						adcInputGroup.style.display = 'flex';
						adcResultCardTitle.textContent = 'ADC读数'; // 恢复卡片标题
						adcValueCard.style.display = 'none'; // 隐藏ADC值卡片
						percentageCard.style.display = 'none'; // 隐藏ADC百分比卡片
						temperatureCard.style.display = 'block'; // 显示温度卡片
						ntcResistanceCard.style.display = 'block'; // 显示NTC电阻卡片

						// 显示模式二：ADC→温度使用的公式
						formula1.style.display = 'none';
						formula2.style.display = 'none';
						formula4Adc.style.display = 'none';
						formula3.style.display = 'block';
						formula4.style.display = 'block';
						formula6.style.display = 'block';

						// 更新参数说明，只显示模式二：ADC→温度需要的参数
						paramsDescription.innerHTML = `
						<strong>参数说明：</strong>
						<ul style="margin: 5px 0 0 15px; padding-left: 20px; text-align: left; list-style-type: disc">
							<li>T：计算得到的当前温度，单位是开尔文 (K)</li>
							<li>ln：自然对数</li>
							<li>R<sub>t</sub>：是在温度T下的NTC电阻值</li>
							<li>T<sub>0</sub>：是参考温度（用户可设置，默认为25°C = 298.15K）</li>
							<li>R<sub>0</sub>：是NTC在参考温度T<sub>0</sub>下的标称电阻值</li>
							<li>B：是B值，由制造商提供</li>
							<li>V<sub>out</sub>：是输出电压，V<sub>CC</sub>是供电电压</li>
							<li>R<sub>fixed</sub>：是固定电阻值</li>
							<li>V<sub>ref</sub>：是ADC的参考电压</li>
							<li>ADC<sub>value</sub>：是MCU读取到的原始ADC值</li>
							<li>ADC<sub>max</sub>：是ADC的最大值</li>
						</ul>
					`;
					}
				}

				// 为所有模式选择单选按钮添加事件监听器
				const modeRadios = document.querySelectorAll('input[name="calc-mode"]');
				modeRadios.forEach((radio) => {
					radio.addEventListener('change', updateInterfaceByMode);
				});

				// 页面加载时初始化界面状态
				window.addEventListener('load', updateInterfaceByMode);
			</script>

			<!-- 公式说明区域 - 小窗口适配 -->
			<div class="mb-4">
				<div class="formula-box">
					<div class="formula-title">计算公式</div>

					<!-- 公式区域 - 小窗口适配 -->
					<div class="mt-3">
						<!-- 模式一：温度→ADC模式使用的公式 (1) -->
						<div id="formula-1" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									word-break: break-all;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(1)</span>
								R<sub>t</sub> = R<sub>0</sub> × e<sup>
									[B × (
									<span style="display: inline-block; text-align: center; vertical-align: middle; width: 28px; font-size: 0.8em">
										<span style="display: block; line-height: 1">1</span>
										<span style="display: block; border-bottom: 1px solid black; line-height: 0.3"></span>
										<span style="display: block; line-height: 1">T</span>
									</span>
									-
									<span style="display: inline-block; text-align: center; vertical-align: middle; width: 28px; font-size: 0.8em">
										<span style="display: block; line-height: 1">1</span>
										<span style="display: block; border-bottom: 1px solid black; line-height: 0.3"></span>
										<span style="display: block; line-height: 1">T<sub>0</sub></span>
									</span>
									)]</sup
								>
							</div>
						</div>
						<!-- 模式一：温度→ADC模式使用的公式 (2) -->
						<div id="formula-2" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(2)</span>
								V<sub>out</sub> = V<sub>CC</sub> ×
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>R<sub>t</sub></span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>(R<sub>fixed</sub> + R<sub>t</sub>)</span>
								</span>
							</div>
						</div>
						<!-- 模式一：温度→ADC模式使用的公式 (3) - ADC转换公式 -->
						<div id="formula-4-adc" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(3)</span>
								ADC<sub>value</sub> =
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>V<sub>out</sub></span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>V<sub>ref</sub></span>
								</span>
								× ADC<sub>max</sub>
							</div>
						</div>
						<!-- 模式二：ADC→温度使用的公式 (1) -->
						<div id="formula-3" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(1)</span>
								R<sub>t</sub> = R<sub>fixed</sub> ×
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>V<sub>out</sub></span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>(V<sub>CC</sub> - V<sub>out</sub>)</span>
								</span>
							</div>
						</div>
						<!-- 模式二：ADC→温度使用的公式 (2) -->
						<div id="formula-4" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(2)</span>
								V<sub>out</sub> =
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>ADC<sub>value</sub></span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>ADC<sub>max</sub></span>
								</span>
								× V<sub>ref</sub>
							</div>
						</div>
						<!-- 模式二：ADC→温度使用的公式 (3) -->
						<div id="formula-6" class="formula-row" style="white-space: nowrap; width: 100%; margin-top: 15px">
							<div
								style="
									background-color: #f0f4ff;
									padding: 15px;
									border-radius: 8px;
									border: 1px solid #d1d5db;
									width: 100%;
									height: auto;
									min-height: 60px;
									display: flex;
									align-items: center;
									justify-content: flex-start;
								"
							>
								<span style="font-weight: bold; color: #0369a1; margin-right: 12px">(3)</span>
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>1</span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>T</span>
								</span>
								=
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>1</span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>T<sub>0</sub></span>
								</span>
								+
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>1</span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>B</span>
								</span>
								× ln(
								<span style="display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle">
									<span>R<sub>t</sub></span>
									<span style="border-bottom: 1px solid black; width: 100%"></span>
									<span>R<sub>0</sub></span>
								</span>
								)
							</div>
						</div>
					</div>
					<!-- 参数说明 -->
					<div
						id="params-description"
						style="margin-top: 15px; background-color: #f1f8e9; padding: 10px; border-radius: 5px; font-size: 0.9em; line-height: 1.5"
					>
						<strong>参数说明：</strong>
						<ul style="margin: 5px 0 0 15px; padding-left: 20px; text-align: left; list-style-type: disc">
							<li>T：待求的当前温度，单位是开尔文 (K)</li>
							<li>ln：自然对数</li>
							<li>R<sub>t</sub>：是在温度T下的NTC电阻值</li>
							<li>T<sub>0</sub>：是参考温度（用户可设置，默认为25°C = 298.15K）</li>
							<li>R<sub>0</sub>：是NTC在参考温度T<sub>0</sub>下的标称电阻值</li>
							<li>B：是B值，由制造商提供</li>
							<li>V<sub>out</sub>：是输出电压，V<sub>CC</sub>是供电电压</li>
							<li>R<sub>fixed</sub>：是固定电阻值</li>
							<li>V<sub>ref</sub>：是ADC的参考电压（通常与Vcc相同，例如3.3V）</li>
							<li>ADC<sub>value</sub>：是MCU读取到的原始ADC值（例如0-4095）</li>
							<li>ADC<sub>max</sub>：是ADC的最大值（对于12位ADC是4095，10位是1023）</li>
						</ul>
					</div>
				</div>
			</div>

			<!-- 输入框容器 - 小窗口单列 -->
			<div class="input-container">
				<!-- 硬件配置分区 -->
				<div class="section-container border rounded-lg p-4 bg-gray-50">
					<h3 class="section-title text-lg font-semibold mb-4 text-gray-700">硬件配置</h3>
					<div class="grid grid-cols-1 gap-4">
						<!-- 参考温度 -->
						<div class="input-group">
							<div class="input-label">T<sub>0</sub>（℃）</div>
							<div class="input-field">
								<input
									type="number"
									id="ntc-reference-temperature"
									value="25"
									min="-50"
									max="200"
									step="0.1"
									placeholder="请输入参考温度"
									oninput="updateReferenceTemperatureK(); if (document.getElementById('real-time-update').checked) ntcDividerCalculate()"
								/>
								<span class="input-unit">°C</span>
							</div>
						</div>

						<!-- 参考温度 (开尔文) -->
						<div class="input-group">
							<div class="input-label">T<sub>0</sub>（K）</div>
							<div class="input-field">
								<input
									type="number"
									id="ntc-reference-temperature-k"
									value="298.15"
									min="223.15"
									max="473.15"
									step="0.01"
									placeholder="请输入参考温度 (开尔文)"
									readonly
									style="background-color: #e0e7ff"
								/>
								<span class="input-unit">K</span>
							</div>
						</div>

						<!-- 参考温度电阻值 R<sub>0</sub> -->
						<div class="input-group">
							<div class="input-label">R<sub>0</sub></div>
							<div
								class="input-field"
								style="
									position: relative;
									display: flex;
									align-items: center;
									background-color: #f8fafc;
									border: 1px solid #e2e8f0;
									border-radius: 8px;
									overflow: hidden;
									padding: 0;
								"
							>
								<input
									type="number"
									id="ntc-reference-resistance"
									value="10"
									min="0.001"
									max="1000"
									step="0.001"
									placeholder="请输入参考温度下的电阻值"
									style="
										width: calc(100% - 3rem);
										text-align: center;
										padding: 0.6rem 0.75rem;
										border: none;
										background: transparent;
										outline: none;
										font-size: 0.9rem;
									"
								/>
								<select
									id="ntc-reference-resistance-unit"
									class="unit-selector"
									style="
										width: 3rem;
										text-align: center;
										background: transparent;
										border: none;
										border-left: 1px solid #e2e8f0;
										font-size: 0.875rem;
										color: #6b7280;
										cursor: pointer;
										padding: 0.6rem 0.25rem;
										transition: all 0.2s ease;
									"
								>
									<option value="ohm">Ω</option>
									<option value="kilo-ohm" selected>kΩ</option>
									<option value="mega-ohm">MΩ</option>
								</select>
							</div>
						</div>

						<!-- 固定电阻 -->
						<div class="input-group">
							<div class="input-label">R<sub>fixed</sub></div>
							<div
								class="input-field"
								style="
									position: relative;
									display: flex;
									align-items: center;
									background-color: #f8fafc;
									border: 1px solid #e2e8f0;
									border-radius: 8px;
									overflow: hidden;
									padding: 0;
								"
							>
								<input
									type="number"
									id="ntc-resistance-fixed-custom"
									value="10"
									min="0.001"
									max="1000"
									step="0.001"
									placeholder="请输入固定电阻值"
									oninput="if (document.getElementById('real-time-update').checked) ntcDividerCalculate()"
									style="
										width: calc(100% - 3rem);
										text-align: center;
										padding: 0.6rem 0.75rem;
										border: none;
										background: transparent;
										outline: none;
										font-size: 0.9rem;
									"
								/>
								<select
									id="ntc-fixed-resistance-unit"
									class="unit-selector"
									style="
										width: 3rem;
										text-align: center;
										background: transparent;
										border: none;
										border-left: 1px solid #e2e8f0;
										font-size: 0.875rem;
										color: #6b7280;
										cursor: pointer;
										padding: 0.6rem 0.25rem;
										transition: all 0.2s ease;
									"
								>
									<option value="ohm">Ω</option>
									<option value="kilo-ohm" selected>kΩ</option>
									<option value="mega-ohm">MΩ</option>
								</select>
							</div>
						</div>

						<!-- 供电电压 -->
						<div class="input-group">
							<div class="input-label">Vcc</div>
							<div class="input-field">
								<input type="number" id="ntc-vcc" value="3.3" min="0.1" max="24" step="0.1" placeholder="请输入供电电压" />
								<span class="input-unit">V</span>
							</div>
						</div>

						<!-- 参考电压 -->
						<div class="input-group">
							<div class="input-label">V<sub>ref</sub></div>
							<div class="input-field">
								<input type="number" id="ntc-supply-voltage" value="3.3" min="0.1" max="24" step="0.1" placeholder="请输入参考电压" />
								<span class="input-unit">V</span>
							</div>
						</div>

						<!-- ADC分辨率 -->
						<div class="input-group">
							<div class="input-label">ADC<sub>max</sub></div>
							<div class="input-field">
								<select id="ntc-adc-resolution" style="text-align: center">
									<option value="8">8位 (0-255)</option>
									<option value="10">10位 (0-1023)</option>
									<option value="12" selected>12位 (0-4095)</option>
									<option value="16">16位 (0-65535)</option>
								</select>
							</div>
						</div>

						<!-- B值 -->
						<div class="input-group">
							<div class="input-label">B值</div>
							<div class="input-field">
								<input type="number" id="ntc-beta" value="3950" min="1000" max="6000" step="1" placeholder="请输入B值" />
								<span class="input-unit">K</span>
							</div>
						</div>
					</div>
				</div>

				<!-- 温度计算分区 -->
				<div class="section-container border rounded-lg p-4 bg-gray-50">
					<h3 class="section-title text-lg font-semibold mb-4 text-gray-700">温度计算</h3>
					<div class="grid grid-cols-1 gap-4">
						<!-- 温度输入 -->
						<div class="input-group">
							<div class="input-label">T（℃)</div>
							<div class="input-field">
								<input
									type="number"
									id="ntc-temperature"
									value="50"
									min="-50"
									max="200"
									step="0.1"
									placeholder="请输入当前温度"
									oninput="updateTemperatureK(); if (document.getElementById('real-time-update').checked) ntcDividerCalculate()"
								/>
								<span class="input-unit">°C</span>
							</div>
						</div>

						<!-- 温度输入 (开尔文) -->
						<div class="input-group">
							<div class="input-label">T（K）</div>
							<div class="input-field">
								<input
									type="number"
									id="ntc-temperature-k"
									value="323.15"
									min="223.15"
									max="473.15"
									step="0.01"
									placeholder="请输入当前温度 (开尔文)"
									readonly
									style="background-color: #e0e7ff"
								/>
								<span class="input-unit">K</span>
							</div>
						</div>

						<!-- Rt输入 (根据第一组公式计算得出) -->
						<div class="input-group">
							<div class="input-label">R<sub>t</sub></div>
							<div
								class="input-field"
								style="
									position: relative;
									display: flex;
									align-items: center;
									background-color: #f8fafc;
									border-radius: 8px;
									overflow: hidden;
									padding: 0;
								"
							>
								<input
									type="number"
									id="ntc-resistance-rt"
									value="10"
									min="0.001"
									max="1000"
									step="0.001"
									placeholder="计算得出的NTC电阻值"
									readonly
									style="
										width: calc(100% - 3rem);
										text-align: center;
										padding: 0.5rem 0.75rem;
										border: none;
										background-color: #e0e7ff;
										outline: none;
									"
								/>
								<select
									id="ntc-resistance-rt-unit"
									class="unit-selector"
									style="
										width: 3rem;
										text-align: center;
										background: transparent;
										border: none;
										border-left: 1px solid #e2e8f0;
										font-size: 0.875rem;
										color: #6b7280;
										cursor: pointer;
										padding: 0.5rem 0.25rem;
										transition: all 0.2s ease;
									"
								>
									<option value="ohm">Ω</option>
									<option value="kilo-ohm" selected>kΩ</option>
									<option value="mega-ohm">MΩ</option>
								</select>
							</div>
						</div>

						<!-- ADC输入 (用于ADC→温度模式) -->
						<div class="input-group" id="adc-input-group">
							<div class="input-label">ADC<sub>value</sub></div>
							<div class="input-field">
								<input type="number" id="ntc-adc-input" value="2000" min="0" max="65535" step="1" placeholder="已知ADC值" />
							</div>
						</div>
					</div>
				</div>
			</div>

			<!-- 操作区域 - 重新布局 -->
			<div class="grid grid-cols-2 gap-4 mb-4">
				<!-- 实时更新复选框 -->
				<div class="bg-white p-3 rounded-lg border border-gray-200">
					<div style="display: flex; align-items: center; justify-content: center">
						<input
							type="checkbox"
							id="real-time-update"
							checked
							style="accent-color: #3b82f6; width: 18px; height: 18px; display: inline-block; margin: 0"
						/>
						<label
							for="real-time-update"
							class="ml-2 text-sm font-medium text-gray-700 cursor-pointer"
							style="display: inline-block; margin: 0; text-align: center; flex: 1"
						>
							实时更新
						</label>
					</div>
				</div>

				<!-- 计算按钮 -->
				<button onclick="ntcDividerCalculate()" id="calculate-button" class="btn-primary"><i class="fa fa-calculator mr-2"></i>计算</button>
			</div>

			<!-- 重置按钮单独一行 -->
			<div class="grid grid-cols-1">
				<button onclick="ntcDividerClear()" class="btn-secondary"><i class="fa fa-refresh mr-2"></i>重置</button>
			</div>

			<!-- 结果区域 - 小窗口单列适配 -->
			<div class="result-cards">
				<!-- 温度结果卡片 -->
				<div class="result-card temperature-card">
					<div class="result-title">T(℃)</div>
					<div class="result-value" id="result-temperature">25.00 °C</div>
				</div>

				<!-- NTC电阻值 -->
				<div class="result-card ntc-resistance-card">
					<div class="result-title">Rt</div>
					<div class="result-value" id="result-ntc-resistance">10000 Ω</div>
				</div>

				<!-- 输出电压 -->
				<div class="result-card voltage-card">
					<div class="result-title">V<sub>out</sub></div>
					<div class="result-value" id="result-output-voltage">1.6500 V</div>
				</div>

				<!-- ADC值 -->
				<div class="result-card adc-value-card">
					<div class="result-title">ADCvalue</div>
					<div class="result-value" id="result-adc-value">512 (0x200)</div>
				</div>

				<!-- ADC百分比 -->
				<div class="result-card percentage-card">
					<div class="result-title">ADC百分比</div>
					<div class="result-value" id="result-adc-percentage">50.00%</div>
				</div>

				<!-- 分压比 -->
				<div class="result-card ratio-card">
					<div class="result-title">分压比</div>
					<div class="result-value" id="result-ratio">0.5000</div>
				</div>
			</div>

			<!-- NTC热敏电阻介绍 -->
			<div class="mt-6 p-4 bg-blue-50 rounded-lg border border-blue-100">
				<h3 class="text-lg font-semibold text-blue-800 mb-2">NTC热敏电阻介绍</h3>
				<p class="text-blue-700">NTC热敏电阻的核心物理特性是：其电阻值随温度升高而呈非线性、指数式下降。</p>
			</div>

			<!-- 页脚 -->
			<footer class="w-full mx-auto mt-6 text-center text-sm text-gray-500">
				<p>版本号: V0.0.1-20251004</p>
			</footer>
		</div>

		<script>
			// 单位转换函数 - 将显示值转换为欧姆（内部计算单位）
			function displayValueToOhms(displayValue, unit) {
				const numValue = parseFloat(displayValue);
				if (isNaN(numValue)) return 0;

				switch(unit) {
					case 'ohm':
						return numValue;
					case 'kilo-ohm':
						return numValue * 1000;
					case 'mega-ohm':
						return numValue * 1000000;
					default:
						return numValue;
				}
			}

			// 单位转换函数 - 将欧姆转换为显示值（根据选择的单位）
			function ohmsToDisplayValue(ohmsValue, unit) {
				switch(unit) {
					case 'ohm':
						return ohmsValue;
					case 'kilo-ohm':
						return ohmsValue / 1000;
					case 'mega-ohm':
						return ohmsValue / 1000000;
					default:
						return ohmsValue;
				}
			}

			// 为单位选择器添加事件监听器
			document.addEventListener('DOMContentLoaded', function() {
				// 为所有单位选择器添加事件监听器
				const unitSelectors = document.querySelectorAll('.unit-selector');
				unitSelectors.forEach(selector => {
					selector.addEventListener('change', function() {
						// 当单位改变时，保持实际电阻值不变，但更新显示值
						const inputId = this.id.replace('-unit', '');
						const inputElement = document.getElementById(inputId);
						if (inputElement && !isNaN(inputElement.value)) {
							// 获取当前显示值对应的欧姆值
							const currentUnit = this.value;
							const currentDisplayValue = parseFloat(inputElement.value);
							const ohmsValue = displayValueToOhms(currentDisplayValue, currentUnit);

							// 当单位改变时，如果是实时更新模式，重新计算
							if (document.getElementById('real-time-update').checked) {
								ntcDividerCalculate();
							}
						}
					});
				});
			});

			// 格式化电阻值
			function formatResistance(resistance) {
				if (resistance >= 1000000) {
					return (resistance / 1000000).toFixed(2) + 'M';
				} else if (resistance >= 1000) {
					return (resistance / 1000).toFixed(2) + 'K';
				} else {
					return resistance.toFixed(0);
				}
			}

			// NTC分压计算器核心功能
			function ntcDividerCalculate() {
				// 结果容器ID映射，确保所有需要更新的元素ID都正确
				const resultElementIds = [
					'result-ntc-resistance',
					'result-output-voltage',
					'result-adc-value',
					'result-adc-percentage',
					'result-ratio',
					'result-temperature' // 添加温度RESULT显示
				];

				// 验证所有结果元素是否存在
				const allElementsExist = resultElementIds.every((id) => {
					const element = document.getElementById(id);
					if (!element) {
						console.warn(`结果元素不存在: ${id}`);
					}
					return !!element;
				});

				if (!allElementsExist) {
					console.error('部分结果元素缺失，无法完成计算结果更新');
					return;
				}

				try {
					// 获取输入值
					const mode = document.querySelector('input[name="calc-mode"]:checked').value;
					const formulaType = document.querySelector('input[name="formula-type"]:checked')?.value || 'ntc-top';
					// 获取固定电阻值（从输入框）
					let referenceResistance;
					const customInput = document.getElementById('ntc-resistance-fixed-custom');
					const fixedResistanceUnit = document.getElementById('ntc-fixed-resistance-unit').value;
					referenceResistance = displayValueToOhms(customInput.value, fixedResistanceUnit);
					const vcc = parseFloat(document.getElementById('ntc-vcc').value); // 供电电压 Vcc
					const supplyVoltage = parseFloat(document.getElementById('ntc-supply-voltage').value); // 参考电压 V_ref
					const beta = parseFloat(document.getElementById('ntc-beta').value); // B值
					// 获取参考电阻（R0）及其单位
					const referenceResistanceUnit = document.getElementById('ntc-reference-resistance-unit').value;
					const resistance25 = displayValueToOhms(document.getElementById('ntc-reference-resistance').value, referenceResistanceUnit); // R_0 (参考温度下的电阻)
					const referenceTemperature = parseFloat(document.getElementById('ntc-reference-temperature').value); // T_0 (参考温度)
					const referenceTemperatureK = referenceTemperature + 273.15; // 参考温度T_0（开尔文）
					const adcResolution = parseInt(document.getElementById('ntc-adc-resolution').value);

					// 输入验证
					if (
						isNaN(referenceTemperature) ||
						isNaN(beta) ||
						isNaN(resistance25) ||
						isNaN(referenceResistance) ||
						isNaN(vcc) ||
						isNaN(supplyVoltage) ||
						isNaN(adcResolution) ||
						referenceResistance <= 0 ||
						vcc <= 0 ||
						supplyVoltage <= 0 ||
						beta <= 0 ||
						resistance25 <= 0 ||
						adcResolution <= 0 ||
						adcResolution > 24
					) {
						console.log('输入验证失败，缺少必要参数或参数无效');
						return; // 确保所有必要参数都有效
					}

					// 变量初始化
					let ntcResistance, outputVoltage, adcValue, temperature, adcPercentage, ratio;
					const adcMaxValue = Math.pow(2, adcResolution) - 1;

					// 根据模式执行不同的计算逻辑
					if (mode === 'temp-to-adc') {
						// 温度→ADC模式（计算ADCvalue）
						temperature = parseFloat(document.getElementById('ntc-temperature').value);
						if (isNaN(temperature)) {
							console.log('温度值无效');
							return;
						}

						// 重新获取所有输入框的实时参数，确保使用最新值
						const currentBeta = parseFloat(document.getElementById('ntc-beta').value);
						const currentVcc = parseFloat(document.getElementById('ntc-vcc').value);
						const currentSupplyVoltage = parseFloat(document.getElementById('ntc-supply-voltage').value);
						const currentFixedResistance = displayValueToOhms(document.getElementById('ntc-resistance-fixed-custom').value, document.getElementById('ntc-fixed-resistance-unit').value);
						const currentResistance25 = displayValueToOhms(document.getElementById('ntc-reference-resistance').value, document.getElementById('ntc-reference-resistance-unit').value);
						const currentReferenceTemperatureK = parseFloat(document.getElementById('ntc-reference-temperature').value) + 273.15;

						// 根据公式（1）计算Rt值（从温度计算电阻）
						const temperatureK = temperature + 273.15; // 转换为开尔文温度
						ntcResistance = currentResistance25 * Math.exp(currentBeta * (1 / temperatureK - 1 / currentReferenceTemperatureK));

						// 根据公式（2）计算输出电压
						outputVoltage = (currentVcc * ntcResistance) / (currentFixedResistance + ntcResistance);

						// 根据公式（4）的反函数计算ADC值
						adcValue = Math.round((outputVoltage / currentSupplyVoltage) * adcMaxValue);
						adcValue = Math.max(0, Math.min(adcMaxValue, adcValue));
						adcPercentage = (adcValue / adcMaxValue) * 100;

					} else if (mode === 'adc-to-temp') {
						// ADC→温度模式
						adcValue = parseInt(document.getElementById('ntc-adc-input').value);
						if (isNaN(adcValue) || adcValue < 0 || adcValue > adcMaxValue) {
							console.log('ADC值无效');
							return;
						}

						// 从ADC值计算输出电压
						adcPercentage = (adcValue / adcMaxValue) * 100;
						outputVoltage = (adcValue / adcMaxValue) * supplyVoltage;

						// 根据公式计算NTC电阻
						if (formulaType === 'ntc-top') {
							// 对于NTC在顶部：V_out = Vcc × R_t/(R_fixed + R_t) → R_t = (V_out × R_fixed) / (Vcc - V_out)
							if (Math.abs(vcc - outputVoltage) > 0.000001) { // 避免除以零
								ntcResistance = (outputVoltage * referenceResistance) / (vcc - outputVoltage);
							} else {
								ntcResistance = resistance25; // 使用默认值避免错误
							}
						} else if (formulaType === 'ntc-rt') {
							// 使用公式：Rt = R_fixed ×（ V_out / (Vcc - V_out)）
							if (Math.abs(vcc - outputVoltage) > 0.000001) { // 避免除以零
								ntcResistance = referenceResistance * (outputVoltage / (vcc - outputVoltage));
							} else {
								ntcResistance = resistance25; // 使用默认值避免错误
							}
						}

						// 从NTC电阻计算温度（逆推B参数公式）
						// Rt = R0 × exp(B × (1/T - 1/T0))
						// 解T: T = 1 / ( (ln(Rt/R0)/B ) + 1/T0 )
						const rtRatio = ntcResistance / resistance25;
						if (rtRatio > 0) {
							const lnRatio = Math.log(rtRatio);
							const inverseTemperatureK = (lnRatio / beta) + (1 / referenceTemperatureK);
							if (inverseTemperatureK > 0) {
								const temperatureK = 1 / inverseTemperatureK;
								temperature = temperatureK - 273.15; // 转换为摄氏度
							} else {
								temperature = 25; // 默认值
							}
						} else {
							temperature = 25; // 默认值
						}
					}

					// 计算分压比
					// 根据电压计算公式，分压比为 V<sub>out</sub>/V<sub>cc</sub> = R<sub>t</sub>/(R<sub>p</sub> + R<sub>t</sub>)
					ratio = ntcResistance / (referenceResistance + ntcResistance);

					// 更新输入框的值以显示计算结果（根据选择的单位）
						const rtInput = document.getElementById('ntc-resistance-rt');
						const rtUnitSelector = document.getElementById('ntc-resistance-rt-unit');
						if (rtInput && rtUnitSelector) {
							const displayValue = ohmsToDisplayValue(ntcResistance, rtUnitSelector.value);
							rtInput.value = displayValue.toFixed(3);
						}

					// 更新结果并添加动画效果
				updateResultWithAnimation('result-ntc-resistance', formatResistance(ntcResistance) + ' Ω');
				updateResultWithAnimation('result-output-voltage', outputVoltage.toFixed(4) + ' V');
				updateResultWithAnimation('result-adc-value', adcValue + ' (0x' + adcValue.toString(16).toUpperCase() + ')');
				updateResultWithAnimation('result-adc-percentage', adcPercentage.toFixed(2) + '%');
				updateResultWithAnimation('result-ratio', ratio.toFixed(4));
				updateResultWithAnimation('result-temperature', temperature.toFixed(2) + ' °C');

					console.log('计算结果已成功更新到输出卡片');
				} catch (error) {
					console.error('计算过程中发生错误:', error);
					// 即使发生错误，也要尝试更新结果卡片显示错误信息
					updateResultWithAnimation('result-ntc-resistance', '计算错误');
					updateResultWithAnimation('result-output-voltage', '计算错误');
					updateResultWithAnimation('result-adc-value', '计算错误');
					updateResultWithAnimation('result-adc-percentage', '计算错误');
					updateResultWithAnimation('result-ratio', '计算错误');
					updateResultWithAnimation('result-temperature', '计算错误');
				} finally {
					// 移除之前可能添加的输入验证错误提示
					const inputs = document.querySelectorAll('.input-wrapper input');
					inputs.forEach((input) => {
						clearInputError(input);
					});
				}
			}

			// 格式化电阻值
			function formatResistance(resistance) {
				if (resistance >= 1000000) {
					return (resistance / 1000000).toFixed(2) + 'M';
				} else if (resistance >= 1000) {
					return (resistance / 1000).toFixed(2) + 'K';
				} else {
					return resistance.toFixed(0);
				}
			}

			// 更新固定电阻值
			function updateFixedResistance() {
				// 简化后的函数，仅触发实时计算
				// 触发实时计算（如果已启用）
				if (document.getElementById('real-time-update').checked) {
					ntcDividerCalculate();
				}
			}

			// 更新参考温度开尔文值
			function updateReferenceTemperatureK() {
				const celsiusInput = document.getElementById('ntc-reference-temperature');
				const kelvinInput = document.getElementById('ntc-reference-temperature-k');

				// 避免循环更新
				if (celsiusInput === document.activeElement) {
					const celsiusValue = parseFloat(celsiusInput.value);
					if (!isNaN(celsiusValue)) {
						const kelvinValue = celsiusValue + 273.15;
						kelvinInput.value = kelvinValue.toFixed(2);
					}
				}
			}

			// 更新参考温度摄氏度值
			function updateReferenceTemperatureC() {
				const celsiusInput = document.getElementById('ntc-reference-temperature');
				const kelvinInput = document.getElementById('ntc-reference-temperature-k');

				// 避免循环更新
				if (kelvinInput === document.activeElement) {
					const kelvinValue = parseFloat(kelvinInput.value);
					if (!isNaN(kelvinValue)) {
						const celsiusValue = kelvinValue - 273.15;
						celsiusInput.value = celsiusValue.toFixed(1);
					}
				}
			}

			// 更新当前温度开尔文值
			function updateTemperatureK() {
				const celsiusInput = document.getElementById('ntc-temperature');
				const kelvinInput = document.getElementById('ntc-temperature-k');

				// 避免循环更新
				if (celsiusInput === document.activeElement) {
					const celsiusValue = parseFloat(celsiusInput.value);
					if (!isNaN(celsiusValue)) {
						const kelvinValue = celsiusValue + 273.15;
						kelvinInput.value = kelvinValue.toFixed(2);
					}
				}
			}

			// 更新当前温度摄氏度值
			function updateTemperatureC() {
				const celsiusInput = document.getElementById('ntc-temperature');
				const kelvinInput = document.getElementById('ntc-temperature-k');

				// 避免循环更新
				if (kelvinInput === document.activeElement) {
					const kelvinValue = parseFloat(kelvinInput.value);
					if (!isNaN(kelvinValue)) {
						const celsiusValue = kelvinValue - 273.15;
						celsiusInput.value = celsiusValue.toFixed(1);
					}
				}
			}

			// 重置功能
			function ntcDividerClear() {
					// 重置所有输入值
				document.getElementById('ntc-temperature').value = '25'; // T (当前温度)
				document.getElementById('ntc-reference-temperature').value = '25'; // T_0 (参考温度)
				document.getElementById('ntc-reference-resistance').value = '10'; // R_0 (参考温度下的电阻, kΩ)
				document.getElementById('ntc-reference-resistance-unit').value = 'kilo-ohm';
				// 重置固定电阻选择
				document.getElementById('ntc-resistance-fixed-select').value = '10000';
				document.getElementById('ntc-resistance-fixed-select').style.display = 'block';
				document.getElementById('ntc-resistance-fixed-custom').value = '10'; // kΩ
				document.getElementById('ntc-fixed-resistance-unit').value = 'kilo-ohm';
				document.getElementById('ntc-resistance-fixed-custom').style.display = 'none';
				document.getElementById('ntc-resistance-rt').value = '10'; // NTC电阻 Rt, kΩ
				document.getElementById('ntc-resistance-rt-unit').value = 'kilo-ohm';
				document.getElementById('ntc-adc-input').value = '2000'; // ADC输入值
				document.getElementById('ntc-vcc').value = '3.3'; // 供电电压 Vcc
				document.getElementById('ntc-supply-voltage').value = '3.3'; // 参考电压 V_ref
				document.getElementById('ntc-beta').value = '3950'; // B值
				document.getElementById('ntc-adc-resolution').value = '12';
				document.getElementById('real-time-update').checked = true;

				// 重置模式和公式选择
					document.getElementById('mode-temp-to-adc').checked = false;
					document.getElementById('mode-adc-to-temp').checked = true;
					document.getElementById('formula-ntc-top').checked = true;

				// 执行计算以更新结果
				ntcDividerCalculate();
			}

			/* 更新结果并添加动画效果 - 参照LED计算器 */
			function updateResultWithAnimation(elementId, value) {
				const element = document.getElementById(elementId);
				if (!element) return;

				// 添加更明显的过渡效果
				element.style.transition = 'all 0.3s ease-in-out';
				element.style.opacity = '0.5';
				element.style.transform = 'scale(0.95)';

				setTimeout(() => {
					element.textContent = value;
					element.style.opacity = '1';
					element.style.transform = 'scale(1)';
				}, 150);
			}

			// 防抖函数，用于优化实时更新性能
			function debounce(func, wait) {
				let timeout;
				return function executedFunction(...args) {
					const later = () => {
						clearTimeout(timeout);
						func(...args);
					};
					clearTimeout(timeout);
					timeout = setTimeout(later, wait);
				};
			}

			// 添加实时计算事件监听
			document.addEventListener('DOMContentLoaded', function () {
				// 获取所有输入元素
				const inputs = [
					document.getElementById('ntc-temperature'),
					document.getElementById('ntc-reference-temperature'),
					document.getElementById('ntc-reference-resistance'),
					document.getElementById('ntc-resistance-fixed'),
					document.getElementById('ntc-vcc'),
					document.getElementById('ntc-supply-voltage'),
					document.getElementById('ntc-beta'),
					document.getElementById('ntc-adc-resolution'),
					document.getElementById('ntc-resistance-rt'),
					document.getElementById('ntc-adc-input'), // 添加ADC输入框
				];

				// 添加模式选择和公式选择单选框到事件监听
					const modeSelectRadios = document.querySelectorAll('input[name="calc-mode"]');
					modeSelectRadios.forEach((radio) => inputs.push(radio));

					const formulaSelectRadios = document.querySelectorAll('input[name="formula-select"]');
					formulaSelectRadios.forEach((radio) => inputs.push(radio));

				const realTimeCheckbox = document.getElementById('real-time-update');
				const calculateButton = document.getElementById('calculate-button');

				// 创建设置错误提示的函数
				function setInputError(input, message) {
					const container = input.closest('.input-wrapper');
					let errorElement = container.querySelector('.input-error');
					if (!errorElement) {
						errorElement = document.createElement('div');
						errorElement.className = 'input-error text-red-500 text-sm mt-1';
						container.appendChild(errorElement);
					}
					errorElement.textContent = message;
					input.classList.add('border-red-500');
				}

				// 创建清除错误提示的函数
						function clearInputError(input) {
							const container = input.closest('.input-wrapper');
							if (container) {
								const errorElement = container.querySelector('.input-error');
								if (errorElement) {
									errorElement.remove();
								}
							}
							input.classList.remove('border-red-500');
						}

				// 输入验证函数
				function validateInput(input) {
					clearInputError(input);
					if (input.tagName === 'INPUT' && input.type === 'number') {
						const value = parseFloat(input.value);
						const min = parseFloat(input.min);
						const max = parseFloat(input.max);

						if (isNaN(value)) {
							setInputError(input, '请输入有效数字');
							return false;
						}
						if (!isNaN(min) && value < min) {
							setInputError(input, `最小值为 ${min}`);
							return false;
						}
						if (!isNaN(max) && value > max) {
							setInputError(input, `最大值为 ${max}`);
							return false;
						}

						// 对于Rt输入，添加特殊的验证说明
						if (input.id === 'ntc-resistance-rt') {
							// Rt值必须大于0
							if (value <= 0) {
								setInputError(input, 'NTC电阻值必须大于0');
								return false;
							}
						}
					}
					return true;
				}

				// 创建防抖版本的计算函数
				const debouncedCalculate = debounce(ntcDividerCalculate, 300);

				// 事件处理函数，根据实时计算选项决定是否触发计算
				function handleInputChange(event) {
					// 验证当前输入
					if (event.target && event.target.tagName === 'INPUT') {
						validateInput(event.target);
					}

					if (realTimeCheckbox.checked) {
						// 使用防抖版本的计算函数
						debouncedCalculate();
					}
				}

				// 为所有输入元素添加事件监听
				inputs.forEach((input) => {
					if (input) {
						// 非实时模式下的输入验证
						input.addEventListener('blur', function () {
							if (!realTimeCheckbox.checked) {
								validateInput(input);
							}
						});

						// 实时模式下的更新
						input.addEventListener('input', handleInputChange);
						input.addEventListener('change', handleInputChange);

						if (input.tagName === 'INPUT') {
							input.addEventListener('keyup', function (event) {
								// 支持回车键触发计算，无论实时计算是否启用
								if (event.key === 'Enter') {
									// 验证所有输入
									let isValid = true;
									inputs.forEach((inp) => {
										if (inp && inp.tagName === 'INPUT') {
											if (!validateInput(inp)) {
												isValid = false;
											}
										}
									});
									if (isValid) {
										ntcDividerCalculate();
									}
								}
							});
						}
					}
				});

				// 更新计算按钮状态的函数
				function updateCalculateButtonState() {
					if (realTimeCheckbox.checked) {
						calculateButton.classList.add('opacity-50', 'cursor-not-allowed');
						calculateButton.disabled = true;
					} else {
						calculateButton.classList.remove('opacity-50', 'cursor-not-allowed');
						calculateButton.disabled = false;
					}
				}

				// 实时计算选项改变时，如果勾选了则立即计算并更新按钮状态
				realTimeCheckbox.addEventListener('change', function () {
					updateCalculateButtonState();
					// 清除所有错误提示
					inputs.forEach((input) => {
						if (input && input.tagName === 'INPUT') {
							clearInputError(input);
						}
					});
					// 无论勾选还是取消勾选，都重新计算一次
					ntcDividerCalculate();
				});

				// 页面加载时初始化按钮状态
				updateCalculateButtonState();

				// 页面加载时初始化计算
				ntcDividerCalculate();
			});

			// 暴露给父页面的接口
			window.ntcDividerCalculate = ntcDividerCalculate;
			window.ntcDividerClear = ntcDividerClear;
		</script>
	</body>
</html>
